<?php
	include_once("adb.php");
	
	class community extends adb{
		function community(){
			adb::adb();
		}
		/**
		*query all communities in the table and store the dataset in $this->result	
		*@return if successful true else false
		*/
		
		function get_all_community(){
			$query="select * from community";
			return $this->query($query);
		}
		
		//add new community
		function add_community($latitude,$longitude,$population,$household,$community_name,$subdistrict_id){
			//write the SQL query and call $this->query()
			$query="insert into community set latitude='$latitude',longitude='$longitude',population='$population',
			household='$household',community_name='$community_name',subdistrict_id='$subdistrict_id'";
			return $this->query($query);
		}
		/**
		*updates the record identified by id 
		*/
		function update_community($latitude,$longitude,$population,$household,$community_name,$subdistrict_id,$community_id){
			//write the SQL query and call $this->query()
			$query="update community set latitude='$latitude',longitude='$longitude',population='$population',
			household='$household',community_name='$community_name',subdistrict_id='$subdistrict_id' where community_id='$community_id'";
			return $this->query($query);
		}
		
		// deletes community
		function delete_community($community_id){
			$query="DELETE FROM community where community_id='$community_id'";
			return $this->query($query);
		}
		
		//retruns community
		function get_community($id){
			$query="select * from community where community_id=$id";
			if(!$this->query($query)){
				return false;
			}
			return $this->fetch();
		}
		
		//search community
		function search_community($community_name){
			$query="select * from community where community_name Like '%$community_name%'";
			$search = $this->query($query);
			return $this->fetch();
		}
		
	}
?>